package com.ztc.ZtcDistributionRatio.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcDistributionRatio.bean.ZtcDistributionRatio;

/**
 * <p>
 * 
 * </p>
 * 
 * @ClassName ZtcDistributionRatioDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("ZtcDistributionRatioDao")
public class ZtcDistributionRatioDao extends BaseDaoImpl<ZtcDistributionRatio> {
	public String save(ZtcDistributionRatio ztcDistributionRatio) {
		ZtcDistributionRatio test = this.findUniqueBy("applicableCondition", ztcDistributionRatio.getApplicableCondition());
		if (test != null) {
			return null;
		} else {
			this.getHibernateTemplate().save(ztcDistributionRatio);
			return ztcDistributionRatio.getId();
		}
	}

	public List<ZtcDistributionRatio> getAllZtcDistributionRatios() {
		return this.getAll();
	}

	public boolean delete(String id) {
		this.removeById(id);
		ZtcDistributionRatio test = this.get(id);
		if (test == null) {
			return true;
		}
		return false;
	}

	public List<ZtcDistributionRatio> searchInfoEquals(String applicableCondition) {
		String sql = "select * from ztc_distribution_ratio where 1=1";
		if (applicableCondition != null) {
			sql += " and applicable_condition='" + applicableCondition + "'";
		}
		List<ZtcDistributionRatio> list = this.currentSession().createNativeQuery(sql,ZtcDistributionRatio.class).getResultList();
		return list;
	}

	public String update(ZtcDistributionRatio ztcDistributionRatio) {
		ZtcDistributionRatio ztcDistributionRatioBean = this.findUniqueBy("id", ztcDistributionRatio.getId());
		ztcDistributionRatioBean.setId(ztcDistributionRatio.getId());
		ztcDistributionRatioBean.setFirstLevelManageRatio(ztcDistributionRatio.getFirstLevelManageRatio());
		ztcDistributionRatioBean.setSecondLevelManageRatio(ztcDistributionRatio.getSecondLevelManageRatio());
		ztcDistributionRatioBean.setThirdLevelManageRatio(ztcDistributionRatio.getThirdLevelManageRatio());
		ztcDistributionRatioBean.setFirstLevelMerchantRatio(ztcDistributionRatio.getFirstLevelMerchantRatio());
		ztcDistributionRatioBean.setSecondLevelMerchantRatio(ztcDistributionRatio.getSecondLevelMerchantRatio());
		ztcDistributionRatioBean.setFirstLevelDistributionRatio(ztcDistributionRatio.getFirstLevelDistributionRatio());
		ztcDistributionRatioBean.setSecondLevelDistributionRatio(ztcDistributionRatio.getSecondLevelDistributionRatio());
		ztcDistributionRatioBean.setThirdLevelDistributionRatio(ztcDistributionRatio.getThirdLevelDistributionRatio());
		ztcDistributionRatioBean.setApplicableCondition(ztcDistributionRatio.getApplicableCondition());
		this.save(ztcDistributionRatioBean);
		if (ztcDistributionRatioBean.getId() != null) {
			return "1";
		}
		return "0";
	}
}